package org.jeecg.modules.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.client.ClientUrlConstant;
import org.jeecg.modules.client.HttpClient;
import org.jeecg.modules.dto.other.*;
import org.jeecg.modules.service.OtherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class OtherServiceImpl implements OtherService {

    private static final Logger log_server = LoggerFactory.getLogger("netty-server");

    @Value("${application.openUrl}")
    private String httpUrl;

    /**
     * 网关程序更新
     * @param stationUpFtpReq
     */
    @Override
    public Result<?> stationUp(StationUpFtpReq stationUpFtpReq) {
        log_server.info("网关程序更新 ========== :{}", JSON.toJSONString(stationUpFtpReq));

        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.station_up_ftp, stationUpFtpReq);
        if (resResult.getCode() != CommonConstant.SC_OK_200){
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }

    /**
     * 车桩程序更新
     * @param stationUpFtpReq
     */
    @Override
    public Result<?> pileUp(StationUpFtpReq stationUpFtpReq) {
        log_server.info("车桩程序更新 ========== :{}", JSON.toJSONString(stationUpFtpReq));
        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.station_up_ftp, stationUpFtpReq);
        if (resResult.getCode() != CommonConstant.SC_OK_200) {
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }

}
